package cn.com.se.业务工具.绩效环评数据导入;

import cn.hutool.core.io.FileUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lingheng
 * @version 1.0
 * @description: TODO
 * @date 2024-2-5 11:23
 */
public class 生成更新环评上级评价下级SQL {

    public static List<Map<String, Object>> mapUpdateData() {
        ExcelReader reader = ExcelUtil.getReader(FileUtil.file("E:\\处理环评数据\\需更新原始数据.xlsx"));
        return reader.readAll();
    }

    public static Map<String, Map<String, Object>> mapEvalData() {
        ExcelReader reader = ExcelUtil.getReader(FileUtil.file("E:\\处理环评数据\\评价数据.xlsx"));
        List<Map<String, Object>> maps = reader.readAll();

        Map<String, Map<String, Object>> result = new HashMap<>();
        for (Map<String, Object> map : maps) {
            String 花名 = (String) map.get("花名");
            result.put(花名, map);
        }
        return result;
    }

    public static void main(String[] args) {
        Map<String, Map<String, Object>> stringMapMap = mapEvalData();

        List<Map<String, Object>> updateMap = mapUpdateData();
        for (Map<String, Object> stringObjectMap : updateMap) {
            String 任务ID = (String) stringObjectMap.get("任务ID");
            String 答案ID = (String) stringObjectMap.get("答案ID");
            String 被评价人 = (String) stringObjectMap.get("被评价人");
            String 评价类型 = (String) stringObjectMap.get("评价类型");


            generateUpdateTaskSql(被评价人, 任务ID);
            generateUpdateEvalSql(答案ID, 评价类型, 被评价人, stringMapMap);
        }


    }

    static List<String> taskIdList = Lists.newArrayList();

    public static void generateUpdateTaskSql(String flowerName, String taskId) {

        if (taskIdList.contains(taskId)) {
            return;
        }
        String sql = "UPDATE hr.MANAGE_EVALUATE_TASK SET STATUS = 'FINISHED',accomplish_date = '2024-02-05 13:00:00',update_date = '2024-02-05 13:00:00' WHERE ID = '" + taskId + "';";


        System.out.println("-- " + flowerName + "数据");
        System.out.println(sql);

        taskIdList.add(taskId);
    }

    public static void generateUpdateEvalSql(String answerId, String type, String flowerName, Map<String, Map<String, Object>> stringMapMap) {


        Map<String, Object> dataMap = stringMapMap.get(flowerName);
        if (StringUtils.isNotBlank(type)) {
            Long socre = (Long) dataMap.get(type);
            String sql = "UPDATE hr.MANAGE_SURVEY_ANSWER SET question_answer = '" + socre + "',answer_flag = '1',valid_flag = '0',update_date = '2024-02-05 13:00:00' WHERE ID = '" + answerId + "';";
            System.out.println(sql);
        } else {
            String sql = "UPDATE hr.MANAGE_SURVEY_ANSWER SET question_answer = '/',answer_flag = '1',valid_flag = '1',update_date = '2024-02-05 13:00:00' WHERE ID = '" + answerId + "';";
            System.out.println(sql);
        }


    }


}
